def f(a): 
    for i in range(2, a):
        if a%i==0:
            return 0
    return 1

a=int(input())
if a<1000 and a>=10000:
    print(0)
else:
    if f(a):
         M=a
    else:
         M=0
         while a!=0:
             x=a%10
             y=a%100
             z=a%1000
             if f(x): M=max(M, x)
             if f(y): M = max(M, y)
             if f(z): M = max(M, z)
             a//=10
    print(M)
